
<?php

//连接数据库
try {
    $db = new PDO('mysql:dbname=books;host=127.0.0.1','root','123456');

    $add= $db->prepare('insert into user (name ,phone,sex,cardID) values(:name,:phone,:sex,:cardID)');
    $data[':name']=$_POST['name'];
    $data[':phone']=$_POST['phone'];
    $data[':sex']=$_POST['sex'];
    $data[':cardID']=$_POST['cardID'];
    if($add->execute($data)){
        echo "<script> alert('添加成功!'); location.href='../html/userQueryAll.php';</script>";

    }else{
        echo "<script> alert('添加失败!'); location.href='../html/addUser.php'</script>";
    }
} catch (PDOException $e) {
    echo 'Connection failed';
}
?>

      